package cvo.chess.tests.pieces;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.List;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import cvo.chess.client.entities.IGameFacade;
import cvo.chess.client.entities.armies.pieces.Knight;
import cvo.chess.client.entities.chessboard.ChessboardCoordinate;
import cvo.chess.client.entities.chessboard.IChessboardCoordinate;
import cvo.chess.client.entities.chessboard.ITile;
import cvo.chess.client.entities.game.Army;
import cvo.chess.client.entities.game.Chessboard;
import cvo.chess.client.entities.game.IPiece;

public class KnightTestPossibleMoves {
	private IGameFacade gf;
	private ITile tile;
	private Chessboard board;
	private IChessboardCoordinate chessco;
	private Army army;
	
	@Before
	public void setUp(){
		gf = mock(IGameFacade.class);
		tile = mock(ITile.class);
		when(tile.getPosition()).thenReturn("A1");
		when(gf.getTileAt("A1")).thenReturn(tile);
		
		army = mock(Army.class);
		when(army.getColor()).thenReturn("WHITE");
		
		
		board = mock(Chessboard.class);
		when(board.getHeight()).thenReturn(8);
		when(board.getWidth()).thenReturn(8);
		
		chessco = mock(IChessboardCoordinate.class);
		
	}
	
	@Test
	public void testMockito(){
		ITile t = gf.getTileAt("A1");
		Assert.assertEquals("Postion must be A1", "A1", t.getPosition());
	}
	
	@Test 
	public void testWhenKnightOnA1() throws Exception{
		IPiece knight = new Knight(gf, army);	
		
		chessco.setA1Notation("A1");
		when(chessco.getRow()).thenReturn(4);
		when(chessco.getCol()).thenReturn(3);
		when(chessco.getA1Notation()).thenReturn("A1");
		when(gf.getPositionOfPiece(knight)).thenReturn(chessco);	
		
		gf.setPieceAtPosition(knight, chessco);
		
		Assert.assertNotNull("List of possible moves may not be null", knight.getPossibleMoves());
		
		Assert.assertFalse("List must contain more possible moves", knight.getPossibleMoves().isEmpty());
		
		List<ChessboardCoordinate> list = knight.getPossibleMoves();
		
		Assert.assertTrue("Does contain B3", list.contains(new ChessboardCoordinate(board, "B3")));
		Assert.assertTrue("Does not contain D4", list.contains(new ChessboardCoordinate(board, "D4")));
		
		Assert.assertFalse("May not be included int possMoves", list.contains(new ChessboardCoordinate(board,"C2")));
		Assert.assertFalse("May not be included int possMoves", list.contains(new ChessboardCoordinate(board,"B2")));
	}
	
	@Test 
	public void testWhenKnightB3() throws Exception{
		IPiece knight = new Knight(gf, army);	
		
		chessco.setA1Notation("B3");
		when(chessco.getRow()).thenReturn(4);
		when(chessco.getCol()).thenReturn(3);
		when(chessco.getA1Notation()).thenReturn("B3");
		when(gf.getPositionOfPiece(knight)).thenReturn(chessco);	
		
		gf.setPieceAtPosition(knight, chessco);
		
		Assert.assertNotNull("List of possible moves may not be null", knight.getPossibleMoves());
		
		Assert.assertFalse("List must contain more possible moves", knight.getPossibleMoves().isEmpty());
		
		List<ChessboardCoordinate> list = knight.getPossibleMoves();
		
		Assert.assertTrue("Does contain D4", list.contains(new ChessboardCoordinate(board, "D4")));
		Assert.assertTrue("Does not contain C2", list.contains(new ChessboardCoordinate(board, "C2")));
		
		Assert.assertFalse("May not be included int possMoves", list.contains(new ChessboardCoordinate(board,"B3")));
		Assert.assertFalse("May not be included int possMoves", list.contains(new ChessboardCoordinate(board,"D2")));
	}
	
	
}
